package day17.myRelect2;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class RelectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //method1();
        //method3();
        //method2();
       // method4();
    }

    private static void method4() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class clazz = Class.forName("day17.myRelect2.Student");
        Constructor constructor=clazz.getConstructor(String.class,int.class );
        constructor.setAccessible(true);
        Student student=(Student) constructor.newInstance("lihua",23);
        System.out.println(student);
    }

    private static void method2() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class clazz = Class.forName("day17.myRelect2.Student");
        Constructor constructor=clazz.getConstructor();
        Student student = (Student) constructor.newInstance();
        System.out.println(student);
    }

    private static void method3() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Class clazz = Class.forName("day17.myRelect2.Student");
        Student student = (Student) clazz.newInstance();
        System.out.println(student);
    }


    private static void method1() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class clazz = Class.forName("day17.myRelect2.Student");
        Constructor constructor = clazz.getDeclaredConstructor(String.class);
        constructor.setAccessible(true);
        Student student = (Student) constructor.newInstance("zhanfsan");
        System.out.println(student);
    }
}
